﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Auros.Categorisation.Models
{
    public class CategoryServiceModel
    {
        public CategoryServiceModel() { }

        public CategoryServiceModel(Category category)
        {
            this.ID = category.ID;
            this.ParentID = category.ParentID.HasValue ? category.ParentID.Value : 0;
            this.Name = category.Name;
            this.LocalizedName = category.LocalizedName;
            this.Description = category.Description;
            this.LocalizedDescription = category.LocalizedDescription;
            this.HasChildren = category.HasChildren;

            this.Children = this.GetChildren(category);
        }

        private IEnumerable<CategoryServiceModel> GetChildren(Category category)
        {
            foreach (var item in category.Children)
            {
                yield return new CategoryServiceModel(item);
            }
        }

        public int ID { get; set; }
        public int ParentID { get; set; }
        public string Name { get; set; }
        public string LocalizedName { get; set; }
        public string Description { get; set; }
        public string LocalizedDescription { get; set; }
        public bool HasChildren { get; set; }
        public IEnumerable<CategoryServiceModel> Children { get; set; }
    }
}